﻿///***************************************************************
/// 시  스  템 : Updms.Crd
/// 단위시스템 : CRD
/// 계      층 : Presentation Layer
/// 프로그램명 : Crd1012m
/// 파  일  명 : Crd1012m.aspx.cs
/// 설      명 : 카드사용내역
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2008-07-21 송시명   최초 작성
/// CH002  2008-09-22 송시명   확정로직 수정
///***************************************************************
using System;
using System.Collections;
using System.Data;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using SMFramework.Data;
using SMFramework.Utility;
using SMFramework.Web.UI.WebControls.Page;

using Base.AppFramework.Web.UI.CommandBar;
using Base.Dac;

using Updms.Crd.Exe;
using Updms.Usr.Exe;


namespace Updms.Crd
{
	public partial class Crd1012m : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		public static readonly string PID = "Crd1012m";
		public static readonly string gs_path_info = "/updms/Crd/" + PID + ".aspx";

		Global global = new Global();
		CommCode.Crd crd = new CommCode.Crd(LANG_SET);
		AccessCheck access = new AccessCheck();

		//페이징
		private int li_cur_page, li_row_count, li_st_page, li_ed_page;
		protected int li_page_size = GRID_PAGESIZE;// 한 페이지에 출력될 행의수

		//검색
		protected string kw1 = "";	//카드명
		protected string kw2 = "";	//계정
		protected string kw3 = "";	//카드사용일(부터)
		protected string kw4 = "";	//카드사용일(까지)
		protected string kw5 = "";	//내용
		protected string kw6 = "";	//비고
		protected string kw7 = "";	//확인

		//메뉴 선택값
		protected string gs_sm = "";

		//외부페이지에서 호출
		protected string gs_external = "";

		//페이지별합계
		decimal ld_amount = 0;

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			try
			{
				SetInit();
				if (!Page.IsPostBack)
				{
					// 최초 화면 로딩시 처리해야 할 부분
					OnPageLoad();
					SearchProcess();
				}
				SetClientScriptNoPostBack();
			}
			catch (Exception ex)
			{
				CallExceptionMsgBoxInAjax(ex);
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetClientScript();
			SetCardInfoList();
			SetBizDiv();
			SetAccount();
			SetSearchParameter();
			SetCardInfo();
			SetPaymntDtList(ddl_search_card_cd.SelectedValue);
			SetCardPaymntDt(DateUtil.GetNow());	//오늘 기준으로 결제예정일 설정
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion

		#region SetClientScript, SetClientScriptNoPostBack

		private void SetClientScript()
		{
			//엔터검색
			ddl_search_card_cd.Attributes.Add("onkeypress", "enterSearchOnPage(event)");
			txt_search_biz_from_dt.Attributes.Add("onkeypress", "enterSearchOnPage(event)");
			txt_search_biz_to_dt.Attributes.Add("onkeypress", "enterSearchOnPage(event)");
			txt_search_contents.Attributes.Add("onkeypress", "enterSearchOnPage(event)");
			txt_search_remark.Attributes.Add("onkeypress", "enterSearchOnPage(event)");

			txt_amount.Attributes.Add("onkeyup", "$(\"txt_amount\").value=addComma($(\"txt_amount\").value);");

			//달력콘트롤 설정
			ce_biz_dt.SelectedDate = DateTime.Now.AddDays(0);
		}

		//포스트백과 무관하게 이벤트 지정
		private void SetClientScriptNoPostBack()
		{
			//계정
			cbl_search_account.Items[0].Attributes.Add("onclick", "checkBoxListCheck('cbl_search_account');");
		}

		#endregion

		#region SetInit, SetSearchParameter, ShowKeywordLabel

		//초기값설정
		private void SetInit()
		{
			lbl_search_flag.Text = "INIT";
			if (Request.QueryString["page"] == null || int.Parse(Request.QueryString["page"]) == 1)
			{
				li_cur_page = 1;
				li_st_page = 0;
				li_ed_page = li_page_size;
			}
			else
			{
				li_cur_page = int.Parse(Request.QueryString["page"]);
				li_st_page = (int.Parse(Request.QueryString["page"]) - 1) * li_page_size;
				li_ed_page = li_st_page + li_page_size;
			}

			gs_sm = (Request.QueryString["sm"] == null || Request.QueryString["sm"].Trim().Length != 7)
					? global.GetDirDepth(PID) : Request.QueryString["sm"].ToString();

			gs_external = String.IsNullOrEmpty(Request.QueryString["external"]) ? "" : Request.QueryString["external"].ToString();
		}

		//검색파라미터
		private void SetSearchParameter()
		{
			switch (lbl_search_flag.Text.Trim().ToUpper())
			{
				case "INIT":
					if (String.IsNullOrEmpty(Request.QueryString["kw1"]))
					{
						kw1 = ddl_search_card_cd.SelectedValue;
					}
					else
					{
						kw1 = Server.UrlDecode(Request.QueryString["kw1"]);
						ddl_search_card_cd.SelectedValue = kw1;
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw2"]))
					{
						kw2 = WebControlUtil.GetCheckBoxListValue(cbl_search_account, 1);
					}
					else
					{
						kw2 = Server.UrlDecode(Request.QueryString["kw2"]);
						WebControlUtil.SetCheckBoxListValue(cbl_search_account, kw2);
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw3"]))
					{
						if (String.IsNullOrEmpty(txt_search_biz_from_dt.Text))
						{
							kw3 = DateUtil.GetMonthEx(-6);	//오늘부터 6개월전
							txt_search_biz_from_dt.Text = kw3;
						}
						else
						{
							kw3 = txt_search_biz_from_dt.Text.Trim();
						}
					}
					else
					{
						kw3 = Server.UrlDecode(Request.QueryString["kw3"]);
						txt_search_biz_from_dt.Text = kw3;
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw4"]))
					{
						if (String.IsNullOrEmpty(txt_search_biz_to_dt.Text))
						{
							kw4 = DateUtil.GetMonthEx(0);	//오늘
							txt_search_biz_to_dt.Text = kw4;
						}
						else
						{
							kw4 = txt_search_biz_to_dt.Text.Trim();
						}
					}
					else
					{
						kw4 = Server.UrlDecode(Request.QueryString["kw4"]);
						txt_search_biz_to_dt.Text = kw4;
					}
					if (String.IsNullOrEmpty(Request.QueryString["kw5"]))
					{
						kw5 = txt_search_contents.Text.Trim();
					}
					else
					{
						kw5 = Server.UrlDecode(Request.QueryString["kw5"]);
						txt_search_contents.Text = kw5;
					}
					if (String.IsNullOrEmpty(Request.QueryString["kw6"]))
					{
						kw6 = txt_search_remark.Text.Trim();
					}
					else
					{
						kw6 = Server.UrlDecode(Request.QueryString["kw6"]);
						txt_search_remark.Text = kw6;
					}
					if (String.IsNullOrEmpty(Request.QueryString["kw7"]))
					{
						kw7 = cb_search_check_yn.Checked ? "Y" : "";
					}
					else
					{
						kw7 = Server.UrlDecode(Request.QueryString["kw7"]);
						cb_search_check_yn.Checked = true;
					}

					
					break;
				case "SEARCH":
					kw1 = ddl_search_card_cd.SelectedValue;
					kw2 = WebControlUtil.GetCheckBoxListValue(cbl_search_account, 1);
					kw3 = String.IsNullOrEmpty(txt_search_biz_from_dt.Text) ? DateUtil.GetMonthEx(-6) : txt_search_biz_from_dt.Text.Trim();
					kw4 = String.IsNullOrEmpty(txt_search_biz_to_dt.Text) ? DateUtil.GetMonthEx(0) : txt_search_biz_to_dt.Text.Trim();
					kw5 = txt_search_contents.Text.Trim();
					kw6 = txt_search_remark.Text.Trim();
					kw7 = cb_search_check_yn.Checked ? "Y" : "";					
					break;
			}
		}

		//검색키워드
		private void ShowKeywordLabel()
		{
			string ls_kw1 = ddl_search_card_cd.SelectedItem.Text;
			string ls_kw2 = WebControlUtil.GetCheckBoxListText(cbl_search_account, 1);

			lbl_search_keyword.Text = ls_kw1 + " / " + ls_kw2 + " / " + kw3 + " ~ " + kw4 + " / " + kw5 + " / " + kw6 + " / " + kw7;
		}

		#endregion

		#region 마스터 Method (SetCardInfoList, SetAccount)

		// 카드정보에서 카드정보를 가져와서 ddl_search_card_cd에 채운다.
		private void SetCardInfoList()
		{
			DataSet lo_ds = new DataSet();
			Crd1010m_NT _Crd1010m_NT = new Crd1010m_NT();

			lo_ds.Merge(_Crd1010m_NT.GetCardInfoList("Y"));

			ddl_search_card_cd.Items.Clear();
			ddl_search_card_cd.DataSource = lo_ds;
			ddl_search_card_cd.DataMember = "UPDMS_CRD_INFO";
			ddl_search_card_cd.DataTextField = "Card_Nm";
			ddl_search_card_cd.DataValueField = "Card_Cd";
			ddl_search_card_cd.DataBind();
		}

		//계정
		private void SetAccount()
		{
			crd.SetAccount(cbl_search_account);
			crd.SetAccount(ddl_account);

			cbl_search_account.Items.Insert(0, new ListItem(GetXmlMsg("STR_019"), "ALL"));	//전체선택
		}

		#endregion

		#region 디테일 Method (SetCardInfo, SetBizDiv, SetPaymntDtList, SetCardPaymntDt)

		//카드정보
		private void SetCardInfo()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_card_cd", typeof(string), ddl_search_card_cd.SelectedValue);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			//카드정보(이미지)
			using (Crd1010m_NT _Crd1010m_NT = new Crd1010m_NT())
			{
				lo_ds.Merge(_Crd1010m_NT.GetCardInfo(lo_dp));
			}

			string ls_card_image = DataSetUtil.GetFldStr(lo_ds, "UPDMS_CRD_INFO", "Attach_File1");
			img_card_image.Src = FILE_PATH_UPLOAD_WEB_PATH + (string.IsNullOrEmpty(ls_card_image) ? "empty.png" : ls_card_image);
		}

		//결제구분
		private void SetBizDiv()
		{
			crd.SetBizDiv(rbl_biz_div);

			//할부는 삭제
			for (int i = 0; i < rbl_biz_div.Items.Count; i++)
			{
				if (rbl_biz_div.Items[i].Value == "AB003")
				{
					rbl_biz_div.Items.RemoveAt(i);
				}
			}
		}
		
		//결제예정일
		private void SetPaymntDtList(string ls_card_cd)
		{
			DataSet lo_ds = new DataSet();
			Crd1011m_NT _Crd1011m_NT = new Crd1011m_NT();

			lo_ds.Merge(_Crd1011m_NT.GetPaymntDtList(ls_card_cd));

			ddl_paymnt_dt.Items.Clear();
			ddl_paymnt_dt.DataSource = lo_ds;
			ddl_paymnt_dt.DataMember = "UPDMS_CRD_PAYMNT_DT";
			ddl_paymnt_dt.DataTextField = "Text";
			ddl_paymnt_dt.DataValueField = "Value";
			ddl_paymnt_dt.DataBind();

			if (ddl_paymnt_dt.Items.Count > 0)
			{
				ibtn_save.Enabled = true;
				ibtn_delete.Enabled = true;
			}
			else
			{
				ibtn_save.Enabled = false;
				ibtn_delete.Enabled = false;
				CallMsgBoxInAjax("MSG_ERR_142");	//지정된 결제일이 없습니다.\n'카드결제일관리'에서 추가해 주세요
			}
		}
		
		//결제일별 결제예정일 지정
		private void SetCardPaymntDt(string ls_biz_dt)
		{
			string ls_paymnt_dt = "";
			DataPack lo_dp = new DataPack();

			Crd1011m_NT _Crd1011m_NT = new Crd1011m_NT();

			lo_dp.AddProperty("ls_card_cd", typeof(string), ddl_search_card_cd.SelectedValue);
			lo_dp.AddProperty("ls_biz_dt", typeof(string), ls_biz_dt);

			ls_paymnt_dt = _Crd1011m_NT.GetPaymntDtByBizDt(lo_dp);

			ddl_paymnt_dt.SelectedValue = ls_paymnt_dt;
		}

		#endregion

		#region 디테일 Method (SetCheckYn, SetCarMgtBtn, SetMoveBtn, SetPaymntDt)

		//확인
		private void SetCheckYn(int li_seq)
		{
			DataPack lo_dp = new DataPack();
			lo_dp.AddProperty("li_seq", typeof(int), li_seq);
			lo_dp.AddProperty("ls_user_id", typeof(string), USER_ID);

			using (Crd1012m_RT _Crd1012m_RT = new Crd1012m_RT())
			{
				int li_return = _Crd1012m_RT.SetCheckYn(lo_dp);
			}
		}

		//계정변경시
		protected void ddl_account_SelectedIndexChanged(object sender, EventArgs e)
		{
			SetCarMgtBtn();
		}
		
		//주유,정비 팝업버튼 활성화
		private void SetCarMgtBtn()
		{
			//주유비, 정비비이면 팝업으로 열 수 있도록 함
			sbtn_car_mgt.Visible = (ddl_account.SelectedValue == "AC017" || ddl_account.SelectedValue == "AC023");
		}

		//이동버튼 활성화
		private void SetMoveBtn(bool lb_visible)
		{
			ibtn_move.Visible = access.CheckPgmUsingGrant(USER_DIV, PID) ? lb_visible : false;
		}

		//결제예정일 바인딩
		private string SetPaymntDt(string paymnt_dt)
		{
			string ls_rslt = string.Empty;

			if (WebControlUtil.CheckDdlValue(ddl_paymnt_dt, paymnt_dt))
			{
				return paymnt_dt;
			}
			else
			{
				CallMsgBoxInAjax("MSG_ERR_162");	//결제예정일이 없습니다.설정관리에서 결제일조회범위를 확인하세요
				return ddl_paymnt_dt.SelectedValue;
			}
		}

		#endregion

		#region CRUD (SelectProcess, InsertProcess, UpdateProcess, DeleteProcess, SearchProcess)

		//조회
		private void SelectProcess()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();
			int li_page_count;

			//검색
			lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
			lo_dp.AddProperty("ls_account", typeof(string), kw2);
			lo_dp.AddProperty("ls_biz_from_dt", typeof(string), kw3);
			lo_dp.AddProperty("ls_biz_to_dt", typeof(string), kw4);
			lo_dp.AddProperty("ls_contents", typeof(string), kw5);
			lo_dp.AddProperty("ls_remark", typeof(string), kw6);
			lo_dp.AddProperty("ls_check_yn", typeof(string), kw7);
			
			try
			{
				using (Crd1012m_NT _Crd1012m_NT = new Crd1012m_NT())
				{
					li_row_count = _Crd1012m_NT.GetSearchCount(lo_dp);	// 검색된 행수
					li_page_count = (int)((li_row_count - 1) / li_page_size) + 1;	// 총페이지수 계산

					//모두보기/페이징
					lo_dp.AddProperty("li_st_page", typeof(Int32), (cb_list_all.Checked) ? 0 : li_st_page);
					lo_dp.AddProperty("li_ed_page", typeof(Int32), (cb_list_all.Checked) ? li_row_count : li_ed_page);
					lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);
					lbl_page.Visible = !cb_list_all.Checked;

					lo_ds.Merge(_Crd1012m_NT.SelectProcess(lo_dp));
				}

				GridView1.DataSource = lo_ds;
				GridView1.DataBind();

				string search_condition = "?sm=" + gs_sm + "&kw1=" + Server.UrlEncode(kw1) + "&kw2=" + Server.UrlEncode(kw2) + "&kw3=" + Server.UrlEncode(kw3) + "&kw4=" + Server.UrlEncode(kw4) + "&kw5=" + Server.UrlEncode(kw5) + "&kw6=" + Server.UrlEncode(kw6) + "&kw7=" + Server.UrlEncode(kw7) + "&page=";

				Pager pager = new Pager(this, ref lbl_page);
				pager.PageNavigation(
					li_cur_page,
					li_page_count,
					gs_path_info + search_condition);

				//결과출력(키워드, 검색행수)
				ShowKeywordLabel();
				lbl_result_count.Text = li_row_count.ToString("#,###,##0");

				//즐겨찾기
				ibtn_favorite.Attributes.Add("onclick", "javascript:goFavoriteSearchPage('" + PID + "','" + search_condition + "');return false;");

				//외부에서 호출되면서 결과값이 1개이면 자동바인딩
				if (gs_external != "" && li_row_count == 1)
				{
					BindingGridView(GridView1, 0);
				}
			}
			catch (Exception ex)
			{
				CallExceptionMsgBoxInAjax(ex);
			}
		}

		//저장
		private void InsertProcess()
		{
			try
			{
				using (Crd1012m_RT _Crd1012m_RT = new Crd1012m_RT())
				{
					int li_return = _Crd1012m_RT.InsertProcess(SetValue());
					string ls_msg_id = (li_return > 0) ? "MSG_INF_007" : "MSG_ERR_105";	//저장되었습니다:저장할 수 없습니다
					CallMsgBoxInAjax(ls_msg_id);

					SearchProcess();
				}
			}
			catch (Exception ex)
			{
				CallExceptionMsgBoxInAjax(ex);
			}
		}
		
		//수정
		private void UpdateProcess()
		{
			try
			{
				using (Crd1012m_RT _Crd1012m_RT = new Crd1012m_RT())
				{
					int li_return = _Crd1012m_RT.UpdateProcess(SetValue());
					string ls_msg_id = (li_return > 0) ? "MSG_INF_006" : "MSG_ERR_104";	//수정되었습니다:수정할 수 없습니다
					CallMsgBoxInAjax(ls_msg_id);

					SearchProcess();
				}
			}
			catch (Exception ex)
			{
				CallExceptionMsgBoxInAjax(ex);
			}
		}

		//삭제
		private void DeleteProcess(string ls_xml)
		{
			try
			{
				using (Crd1012m_RT _Crd1012m_RT = new Crd1012m_RT())
				{
					int li_return = _Crd1012m_RT.DeleteProcess(ls_xml);
					string ls_msg_id = (li_return > 0) ? "MSG_INF_004" : "MSG_ERR_103";	//삭제되었습니다:삭제할 수 없습니다
					CallMsgBoxInAjax(ls_msg_id);

					SearchProcess();
				}
			}
			catch (Exception ex)
			{
				CallExceptionMsgBoxInAjax(ex);
			}
		}

		//확정
		private void ConfirmProcess(int li_seq, string ls_confirm_yn)
		{
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("li_seq", typeof(int), li_seq);
			lo_dp.AddProperty("ls_user_id", typeof(string), USER_ID);
			
			try
			{
				using (Crd1012m_RT _Crd1012m_RT = new Crd1012m_RT())
				{
					int li_return = _Crd1012m_RT.ConfirmProcess(lo_dp);	// 확정처리 ↔ 확정취소
					string ls_msg_id = (ls_confirm_yn == "N") ? "MSG_INF_008" : "MSG_INF_020";//확정되었습니다:해제되었습니다
					ls_msg_id = (li_return > 0) ? ls_msg_id : "MSG_ERR_106";	//확정(해제)되었습니다:확정할 수 없습니다

					CallMsgBoxInAjax(ls_msg_id);
				}
			}
			catch (Exception ex)
			{
				CallExceptionMsgBoxInAjax(ex);
			}
		}

		//검색
		private void SearchProcess()
		{
			lbl_search_flag.Text = "SEARCH";
			SetSearchParameter();
			ClearValue();

			SelectProcess();
		}

		#endregion

		#region SetValue, ClearValue

		//SetValue
		private DataPack SetValue()
		{
			DataPack lo_dp = new DataPack();
			
			lo_dp.AddProperty("Seq",			typeof(string), lbl_pk.Text);
			lo_dp.AddProperty("Card_Cd",		typeof(string), ddl_search_card_cd.SelectedValue);
			lo_dp.AddProperty("Biz_Div",		typeof(string), rbl_biz_div.SelectedValue);
			lo_dp.AddProperty("Account",		typeof(string), ddl_account.SelectedValue);
			lo_dp.AddProperty("Contents",		typeof(string), txt_contents.Text);
			lo_dp.AddProperty("Amount",			typeof(string), ConversionUtil.ExtractNumberStr(txt_amount.Text));
			lo_dp.AddProperty("Biz_Dt",			typeof(string), txt_biz_dt.Text);
			lo_dp.AddProperty("Paymnt_Dt",		typeof(string), ddl_paymnt_dt.SelectedValue);
			lo_dp.AddProperty("Confirm_Yn",		typeof(string), "");
			lo_dp.AddProperty("Remark",			typeof(string), ConversionUtil.DefaultValue(txt_remark.Text));
			lo_dp.AddProperty("Latitude",		typeof(string), ConversionUtil.DefaultValue(txt_latitude.Text, ""));
			lo_dp.AddProperty("Longitude",		typeof(string), ConversionUtil.DefaultValue(txt_longitude.Text, ""));
			lo_dp.AddProperty("Create_User",	typeof(string), USER_ID);
			lo_dp.AddProperty("Create_Dt",		typeof(string), "");
			lo_dp.AddProperty("Update_User",	typeof(string), USER_ID);
			lo_dp.AddProperty("Update_Dt",		typeof(string), "");

			return lo_dp;
		}

		//ClearValue
		private void ClearValue()
		{
			lbl_pk.Text					= "";
			h_no.Value					= "";
			rbl_biz_div.SelectedIndex	= 0;
			ddl_account.SelectedIndex	= 0;
			txt_contents.Text			= "";
			txt_amount.Text				= "";
			ce_biz_dt.SelectedDate		= DateTime.Now.AddDays(0);
			txt_remark.Text				= "";
			txt_latitude.Text			= "";
			txt_longitude.Text			= "";
			ibtn_move.Visible			= false;
		}

		#endregion

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				try
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_BASE);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
					//사용권한별 버튼처리
					PagePreRender.SetVisibleCtrl(this, access.CheckPgmUsingGrant(USER_DIV, PID), access.GetVisibleCtrl(PID));
				}
				catch(Exception ex)
				{
					CallExceptionMsgBoxInAjax(ex);
				}
			}
			ChangePageMode();

			//페이지모드 처리
			string ls_class = String.IsNullOrEmpty(lbl_pk.Text) ? "sbtn sbtn_mode_i" : "sbtn sbtn_mode_u";
			string ls_title = String.IsNullOrEmpty(lbl_pk.Text) ? "입력" : "수정";
			btn_chg_mode.Attributes.Add("class", ls_class);
			btn_chg_mode.Attributes.Add("title", ls_title);
		}

		// ChangePageMode
		private void ChangePageMode()
		{
			SetGridViewHeader(global.GetColumnListByPgmId(PID, LANG_SET));
		}

		#endregion

		#region GridView이벤트

		//RowDataBound
		protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			GridView gv = (GridView)sender;

			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				//마우스올렸을 때
				e.Row.Attributes.Add("onmouseover", "overBackground('GridView1', " + (e.Row.RowIndex + 1) + ")");
				e.Row.Attributes.Add("onmouseout", "outBackground('GridView1', 1)");

				//번호
				e.Row.Cells[1].Text	= cb_list_all.Checked
					? (li_row_count - e.Row.RowIndex).ToString() 
					: ((li_row_count - ((li_cur_page - 1) * li_page_size)) - e.Row.RowIndex).ToString();

				e.Row.Cells[11].Attributes.Add("title", GridView1.DataKeys[e.Row.RowIndex].Values["Remark"].ToString());

				//삭제가능한 항목만 체크박스 활성화
				HtmlInputCheckBox cb = (HtmlInputCheckBox)e.Row.Cells[0].Controls[1];
				cb.Disabled = (gv.DataKeys[e.Row.RowIndex].Values["Confirm_Yn"].ToString() == "Y");
				
				//페이지별 합계
				ld_amount += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Amount"));
			}

			//Footer에 합계 바인딩
			if (e.Row.RowType == DataControlRowType.Footer)
			{
				e.Row.Cells[0].Text = "Total";
				e.Row.Cells[0].Attributes.Add("class", "total");
				e.Row.Cells[0].ColumnSpan = 7;
				e.Row.Cells[1].Visible = false;
				e.Row.Cells[2].Visible = false;
				e.Row.Cells[3].Visible = false;
				e.Row.Cells[4].Visible = false;
				e.Row.Cells[5].Visible = false;
				e.Row.Cells[6].Visible = false;
				e.Row.Cells[7].Visible = false;
				e.Row.Cells[8].Visible = false;
				e.Row.Cells[9].Visible = false;
				e.Row.Cells[10].Visible = false;
				e.Row.Cells[11].Visible = false;
				e.Row.Cells[12].Text = ld_amount.ToString("#,###,##0");
				e.Row.Cells[12].Attributes.Add("class", "money");
				e.Row.Cells[13].Text = "";
				e.Row.Cells[13].Attributes.Add("class", "none");
				e.Row.Cells[13].ColumnSpan = 4;
				e.Row.Cells[14].Visible = false;
				e.Row.Cells[15].Visible = false;
				e.Row.Cells[16].Visible = false;
				e.Row.Cells[17].Visible = false;
				e.Row.Cells[18].Visible = false;
			}
		}

		//RowCommand
		protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
		{
			GridViewRow row = (GridViewRow)(((Control)e.CommandSource).NamingContainer);
			BindingGridView(sender, row.RowIndex);
		}

		//결과값 바인딩
		private void BindingGridView(object sender, int targetRow)
		{
			GridView gv = (GridView)sender;
			GridViewRow row = gv.Rows[targetRow];

			LinkButton lbtn_rc = (LinkButton)gv.Rows[targetRow].FindControl("lbtn_rc");

			//row.Cells[0].Text.ToString();														//0.체크박스
			h_no.Value = row.Cells[1].Text.ToString();											//1.번호
			lbl_pk.Text = gv.DataKeys[row.RowIndex].Values["Seq"].ToString();					//2.Seq
			ddl_search_card_cd.SelectedValue = gv.DataKeys[row.RowIndex].Values["Card_Cd"].ToString();	//3.Card_Cd
																								//4.Card_Cd_Nm
																								//5.Check_Yn
																								//6.Check_Yn_Icon
			rbl_biz_div.SelectedValue = gv.DataKeys[row.RowIndex].Values["Biz_Div"].ToString();	//7.Biz_Div
																								//8.Biz_Div_Nm
			ddl_account.SelectedValue = gv.DataKeys[row.RowIndex].Values["Account"].ToString();	//9.Account
																								//10.Account_Nm
			txt_contents.Text = lbtn_rc.Text;													//11.Contents (template)
			txt_amount.Text = row.Cells[12].Text.Trim();										//12.Amount
			ce_biz_dt.SelectedDate = Convert.ToDateTime(row.Cells[13].Text.Trim());				//13.Biz_Dt
			ddl_paymnt_dt.SelectedValue = SetPaymntDt(row.Cells[14].Text.Trim());				//14.Paymnt_Dt
			lbl_confirm_yn.Text = gv.DataKeys[row.RowIndex].Values["Confirm_Yn"].ToString();	//15.Confirm_Yn
																								//16.Confirm_Yn_Icon
			txt_remark.Text = gv.DataKeys[row.RowIndex].Values["Remark"].ToString();			//17.Remark
			txt_latitude.Text = gv.DataKeys[row.RowIndex].Values["Latitude"].ToString();		//18.Latitude
			txt_longitude.Text = gv.DataKeys[row.RowIndex].Values["Longitude"].ToString();		//19.Longitude

			//확정되지않은 항목만 이동가능
			SetMoveBtn(lbl_confirm_yn.Text != "Y");
			SetCarMgtBtn();
		}

		#endregion

		#region 버튼이벤트

		//검색
		protected void ibtn_search_Click(object sender, EventArgs e)
		{
			SearchProcess();
			SetCardInfo();
			SetPaymntDtList(ddl_search_card_cd.SelectedValue);
			SetCardPaymntDt(txt_biz_dt.Text);
		}

		//저장
		protected void ibtn_save_Click(object sender, EventArgs e)
		{
			if (global.CheckSaveMode("UPDMS_CRD_ITEM_BIZ", "Seq", lbl_pk.Text.Trim()))
			{
				if (lbl_confirm_yn.Text == "N")	//확정여부가 Y이면 수정불가
				{
					UpdateProcess();
				}
				else
				{
					CallMsgBoxInAjax("MSG_ERR_108");	// 확정된 항목은 수정할 수 없습니다
				}
			}
			else
			{
				InsertProcess();
			}
			sbtn_car_mgt.Visible = false;
		}

		//삭제
		protected void ibtn_delete_Click(object sender, EventArgs e)
		{
			StringBuilder sb = new StringBuilder();

			sb.Append("<UPDMS>");

			for (int i = 0; i < GridView1.Rows.Count; i++)
			{
				GridViewRow row = GridView1.Rows[i];
				HtmlInputCheckBox cb = (HtmlInputCheckBox)row.FindControl("cb_check");

				if (cb.Checked)
				{
					string ls_seq = GridView1.DataKeys[i].Values["Seq"].ToString();
					string ls_confirm_yn = GridView1.DataKeys[i].Values["Confirm_Yn"].ToString();
					sb.Append("<UPDMS_CRD_ITEM_BIZ>");
					sb.Append("<Seq>" + ls_seq + "</Seq>");
					sb.Append("<Confirm_Yn>" + ls_confirm_yn + "</Confirm_Yn>");
					sb.Append("</UPDMS_CRD_ITEM_BIZ>");
				}
			}
			sb.Append("</UPDMS>");

			DeleteProcess(sb.ToString());
		}

		//엑셀
		protected void ibtn_excel_Click(object sender, EventArgs e)
		{
			SetSearchParameter();

			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_card_cd", typeof(string), kw1);
			lo_dp.AddProperty("ls_account", typeof(string), kw2);
			lo_dp.AddProperty("ls_biz_from_dt", typeof(string), kw3);
			lo_dp.AddProperty("ls_biz_to_dt", typeof(string), kw4);
			lo_dp.AddProperty("ls_contents", typeof(string), kw5);
			lo_dp.AddProperty("ls_remark", typeof(string), kw6);
			lo_dp.AddProperty("ls_check_yn", typeof(string), kw7);

			using (Crd1012m_NT _Crd1012m_NT = new Crd1012m_NT())
			{
				li_row_count = _Crd1012m_NT.GetSearchCount(lo_dp);

				lo_dp.AddProperty("li_st_page", typeof(Int32), 0);
				lo_dp.AddProperty("li_ed_page", typeof(Int32), li_row_count);
				lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

				lo_ds.Merge(_Crd1012m_NT.SelectProcess(lo_dp));
			}
			string fileName = PID + "(" + global.GetMenuTitle(PID, LANG_SET) + ")";
			ExcelUtil.CreateExcelFileX(this.Page, fileName, lo_ds, SetExcelHeaderX(global.GetColumnListByPgmId(PID, LANG_SET)));
		}

		//확인(리스트에서)
		protected void lbtn_check_yn_Click(object sender, EventArgs e)
		{
			SetCheckYn(Convert.ToInt32(h_seq.Value));
			SearchProcess();
		}

		//확정(리스트에서)
		protected void lbtn_confirm_Click(object sender, EventArgs e)
		{
			using (AccessCheck access = new AccessCheck())
			{
				if (access.CheckPgmUsingGrant(USER_DIV, PID))
				{
					ConfirmProcess(Convert.ToInt32(h_seq.Value), h_confirm_yn.Value);
					SearchProcess();
				}
				else
				{
					CallMsgBoxInAjax("MSG_ERR_109");	//작업에 필요한 권한이 없습니다
				}
			}
		}

		//결제예정일 계산
		protected void lbtn_paymnt_dt_Click(object sender, EventArgs e)
		{
			if (ddl_paymnt_dt.Items.Count > 0)
			{
				SetCardPaymntDt(txt_biz_dt.Text);
			}
			else
			{
				CallMsgBoxInAjax("MSG_ERR_142");	//지정된 결제일이 없습니다.\n'카드결제일관리'에서 추가해 주세요
			}
		}

		//모두보기
		protected void cb_list_all_CheckedChanged(object sender, EventArgs e)
		{
			SearchProcess();
		}

		//디테일 초기화
		protected void lbtn_init_detail_Click(object sender, EventArgs e)
		{
			ClearValue();
		}

		//페이지모드변경
		protected void lbtn_chg_mode_Click(object sender, EventArgs e)
		{
			h_no.Value = "";
			lbl_pk.Text = "";
			ibtn_move.Visible = false;
		}

		#endregion

	}
}
